
var dateUtils = (function () {

    var __class = function () { this.__self = this; };
    __class.prototype.getSelf = function (str) {
        return this.__self;
    }

    /*
        *  获取13位当前时间戳
        *  @param  无
        *  @retrun number  13位当前时间戳
        */
    __class.prototype.timeStamp = function () {
        var time1;
        var date = new Date();
        // 有三种方式获取
        if (date.getTime) {
            time1 = date.getTime();
        } else if (date.valueOf) {
            time1 = date.valueOf();
        } else if (Date.parse) {
            time1 = Date.parse(date)
        }
        return time1;
    }

    /*
    *  将时间戳转换为时间字符串
    *  @param  time number 13位时间戳
    *  @param  flag boolean 可选参数，如果为true则返回json形式：
    *  @retrun string 2018-12-03 12:38:45  时间字符串
    */
    __class.prototype.datastring = function (time, flag) {
        var date = new Date(time);
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hours = date.getHours();
        var mixins = date.getMinutes();
        var second = date.getSeconds();
        month = month < 10 ? "0" + month : month;

        return {y:year,m:month};    //只返回年月，自定义

        // day = day < 10 ? "0" + day : day;
        // mixins = mixins < 10 ? "0" + mixins : mixins;
        // second = second < 10 ? "0" + second : second;
        // if (flag) {
        //     return { y: year, m: month, d: day, h: hours, M: mixins, s: second };
        // } else {
        //     return year + "-" + month + "-" + day + " " + hours + ":" + mixins + ":" + second;
        // }
    };
    __class.prototype.dateObj = function (time, flag) {
        var date = new Date(time);
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hours = date.getHours();
        var mixins = date.getMinutes();
        var second = date.getSeconds();
        month = month < 10 ? "0" + month : month;

        day = day < 10 ? "0" + day : day;
        mixins = mixins < 10 ? "0" + mixins : mixins;
        second = second < 10 ? "0" + second : second;
        if (flag) {
            return { y: year, m: month, d: day, h: hours, M: mixins, s: second };
        } else {
            return year + "-" + month + "-" + day + " " + hours + ":" + mixins + ":" + second;
        }
    };

    return new __class();
})();